const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  // 跳转到支付成功
  toPaymentSu: function () {
    let orderNo = this.data.orderNo

    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/pay/wechat/paySign',
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        "memberId": app.globalData.userInfo.id,
        "outTradeNo": orderNo
      },
      success: function (res) {
        let timeStamp = res.data.result.timeStamp
        let nonceStr = res.data.result.nonceStr
        let package1 = res.data.result.package_
        let signType = res.data.result.signType
        let paySign = res.data.result.paySign

        if (res.data.code != 0) {
          wx.showToast({
            title: "支付异常",
            icon: 'none',
            duration: 1500
          })
        } else {
          console.log("微信签名" + paySign)
          wx.requestPayment({
            timeStamp: timeStamp,
            nonceStr: nonceStr,
            package: package1,
            signType: signType,
            paySign: paySign,
            'success': function (res) {
              wx.navigateTo({
                url: '../payment-success/payment-success'
              })
            },
            'fail': function (res) {
             
            }
          })
          console.log("返回的结果" + res.data.result.timeStamp)
        }


      }
    })
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.orderIds)
    this.setData({
      orderIds: options.orderIds,
      subAmount: options.subAmount
    }); 
    let that = this
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/pay/prepay',
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        "orderIds": that.data.orderIds
      },
      success: function (res) {
        console.log("返回的" + res.data.result.orderNo)
        that.setData({
          orderNo: res.data.result.orderNo,
          subAmount: res.data.result.subAmount
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '琼崖租车',
      path: '/pages/index/index'
    }
  }
})